{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "一、数据说明： Capital Bikeshare （美国Washington, D.C.的一个共享单车公司）提供的共享单车数据。数据包含每天的日期、天气等信息，需要预测每天的共享单车骑行量。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 数据读取及基本处理\n",
    "import pandas as pd\n",
    "import numpy as np\n",
    "\n",
    "# plotting\n",
    "import seaborn as sn\n",
    "import matplotlib.pyplot as plt\n",
    "%matplotlib inline\n",
    "\n",
    "# setting params\n",
    "params = {'legend.fontsize': 'x-large',\n",
    "          'figure.figsize': (30, 10),\n",
    "          'axes.labelsize': 'x-large',\n",
    "          'axes.titlesize':'x-large',\n",
    "          'xtick.labelsize':'x-large',\n",
    "          'ytick.labelsize':'x-large'}\n",
    "\n",
    "sn.set_style('whitegrid')\n",
    "sn.set_context('talk')\n",
    "\n",
    "plt.rcParams.update(params)\n",
    "pd.options.display.max_colwidth = 600\n",
    "\n",
    "# pandas display data frames as tables\n",
    "from IPython.display import display, HTML"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 读入数据\n",
    "train = pd.read_csv(\"day.csv\")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "字段说明: \n",
    "- Instant记录号\n",
    "- Dteday：日期\n",
    "- Season：季节（1=春天、2=夏天、3=秋天、4=冬天）\n",
    "- yr：年份，(0: 2011, 1:2012)\n",
    "- mnth：月份( 1 to 12)\n",
    "- holiday：是否是节假日\n",
    "- weekday：星期中的哪天，取值为0～6\n",
    "- workingday：是否工作日：1=工作日，0=非工作日\n",
    "- weathersit：天气（1：晴天，多云 ",
    "2：雾天，阴天 ",
    "3：小雪，小雨 ",
    "4：大雨，大雪，大雾）\n",
    "- temp：气温摄氏度\n",
    "- atemp：体感温度\n",
    "- hum：湿度\n",
    "- windspeed：风速\n",
    "- casual：非注册用户个数\n",
    "- registered：注册用户个数\n",
    "- cnt：给定日期（天）时间（每小时）总租车人数，响应变量y （cnt = casual + registered）\n",
    "\n",
    "casual、registered和cnt三个特征均为要预测的y，作业里只需对cnt进行预测"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>instant</th>\n",
       "      <th>dteday</th>\n",
       "      <th>season</th>\n",
       "      <th>yr</th>\n",
       "      <th>mnth</th>\n",
       "      <th>holiday</th>\n",
       "      <th>weekday</th>\n",
       "      <th>workingday</th>\n",
       "      <th>weathersit</th>\n",
       "      <th>temp</th>\n",
       "      <th>atemp</th>\n",
       "      <th>hum</th>\n",
       "      <th>windspeed</th>\n",
       "      <th>casual</th>\n",
       "      <th>registered</th>\n",
       "      <th>cnt</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>2011-01-01</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>6</td>\n",
       "      <td>0</td>\n",
       "      <td>2</td>\n",
       "      <td>0.344167</td>\n",
       "      <td>0.363625</td>\n",
       "      <td>0.805833</td>\n",
       "      <td>0.160446</td>\n",
       "      <td>331</td>\n",
       "      <td>654</td>\n",
       "      <td>985</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>1</td>\n",
       "      <td>2</td>\n",
       "      <td>2011-01-02</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>2</td>\n",
       "      <td>0.363478</td>\n",
       "      <td>0.353739</td>\n",
       "      <td>0.696087</td>\n",
       "      <td>0.248539</td>\n",
       "      <td>131</td>\n",
       "      <td>670</td>\n",
       "      <td>801</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>2</td>\n",
       "      <td>3</td>\n",
       "      <td>2011-01-03</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>0.196364</td>\n",
       "      <td>0.189405</td>\n",
       "      <td>0.437273</td>\n",
       "      <td>0.248309</td>\n",
       "      <td>120</td>\n",
       "      <td>1229</td>\n",
       "      <td>1349</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>3</td>\n",
       "      <td>4</td>\n",
       "      <td>2011-01-04</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>2</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>0.200000</td>\n",
       "      <td>0.212122</td>\n",
       "      <td>0.590435</td>\n",
       "      <td>0.160296</td>\n",
       "      <td>108</td>\n",
       "      <td>1454</td>\n",
       "      <td>1562</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>4</td>\n",
       "      <td>5</td>\n",
       "      <td>2011-01-05</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>3</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>0.226957</td>\n",
       "      <td>0.229270</td>\n",
       "      <td>0.436957</td>\n",
       "      <td>0.186900</td>\n",
       "      <td>82</td>\n",
       "      <td>1518</td>\n",
       "      <td>1600</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   instant      dteday  season  yr  mnth  holiday  weekday  workingday  \\\n",
       "0        1  2011-01-01       1   0     1        0        6           0   \n",
       "1        2  2011-01-02       1   0     1        0        0           0   \n",
       "2        3  2011-01-03       1   0     1        0        1           1   \n",
       "3        4  2011-01-04       1   0     1        0        2           1   \n",
       "4        5  2011-01-05       1   0     1        0        3           1   \n",
       "\n",
       "   weathersit      temp     atemp       hum  windspeed  casual  registered  \\\n",
       "0           2  0.344167  0.363625  0.805833   0.160446     331         654   \n",
       "1           2  0.363478  0.353739  0.696087   0.248539     131         670   \n",
       "2           1  0.196364  0.189405  0.437273   0.248309     120        1229   \n",
       "3           1  0.200000  0.212122  0.590435   0.160296     108        1454   \n",
       "4           1  0.226957  0.229270  0.436957   0.186900      82        1518   \n",
       "\n",
       "    cnt  \n",
       "0   985  \n",
       "1   801  \n",
       "2  1349  \n",
       "3  1562  \n",
       "4  1600  "
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 查看数据信息\n",
    "train.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "<class 'pandas.core.frame.DataFrame'>\n",
      "RangeIndex: 731 entries, 0 to 730\n",
      "Data columns (total 16 columns):\n",
      "instant       731 non-null int64\n",
      "dteday        731 non-null object\n",
      "season        731 non-null int64\n",
      "yr            731 non-null int64\n",
      "mnth          731 non-null int64\n",
      "holiday       731 non-null int64\n",
      "weekday       731 non-null int64\n",
      "workingday    731 non-null int64\n",
      "weathersit    731 non-null int64\n",
      "temp          731 non-null float64\n",
      "atemp         731 non-null float64\n",
      "hum           731 non-null float64\n",
      "windspeed     731 non-null float64\n",
      "casual        731 non-null int64\n",
      "registered    731 non-null int64\n",
      "cnt           731 non-null int64\n",
      "dtypes: float64(4), int64(11), object(1)\n",
      "memory usage: 91.5+ KB\n"
     ]
    }
   ],
   "source": [
    "train.info()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>instant</th>\n",
       "      <th>season</th>\n",
       "      <th>yr</th>\n",
       "      <th>mnth</th>\n",
       "      <th>holiday</th>\n",
       "      <th>weekday</th>\n",
       "      <th>workingday</th>\n",
       "      <th>weathersit</th>\n",
       "      <th>temp</th>\n",
       "      <th>atemp</th>\n",
       "      <th>hum</th>\n",
       "      <th>windspeed</th>\n",
       "      <th>casual</th>\n",
       "      <th>registered</th>\n",
       "      <th>cnt</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <td>count</td>\n",
       "      <td>731.000000</td>\n",
       "      <td>731.000000</td>\n",
       "      <td>731.000000</td>\n",
       "      <td>731.000000</td>\n",
       "      <td>731.000000</td>\n",
       "      <td>731.000000</td>\n",
       "      <td>731.000000</td>\n",
       "      <td>731.000000</td>\n",
       "      <td>731.000000</td>\n",
       "      <td>731.000000</td>\n",
       "      <td>731.000000</td>\n",
       "      <td>731.000000</td>\n",
       "      <td>731.000000</td>\n",
       "      <td>731.000000</td>\n",
       "      <td>731.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>mean</td>\n",
       "      <td>366.000000</td>\n",
       "      <td>2.496580</td>\n",
       "      <td>0.500684</td>\n",
       "      <td>6.519836</td>\n",
       "      <td>0.028728</td>\n",
       "      <td>2.997264</td>\n",
       "      <td>0.683995</td>\n",
       "      <td>1.395349</td>\n",
       "      <td>0.495385</td>\n",
       "      <td>0.474354</td>\n",
       "      <td>0.627894</td>\n",
       "      <td>0.190486</td>\n",
       "      <td>848.176471</td>\n",
       "      <td>3656.172367</td>\n",
       "      <td>4504.348837</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>std</td>\n",
       "      <td>211.165812</td>\n",
       "      <td>1.110807</td>\n",
       "      <td>0.500342</td>\n",
       "      <td>3.451913</td>\n",
       "      <td>0.167155</td>\n",
       "      <td>2.004787</td>\n",
       "      <td>0.465233</td>\n",
       "      <td>0.544894</td>\n",
       "      <td>0.183051</td>\n",
       "      <td>0.162961</td>\n",
       "      <td>0.142429</td>\n",
       "      <td>0.077498</td>\n",
       "      <td>686.622488</td>\n",
       "      <td>1560.256377</td>\n",
       "      <td>1937.211452</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>min</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>0.059130</td>\n",
       "      <td>0.079070</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.022392</td>\n",
       "      <td>2.000000</td>\n",
       "      <td>20.000000</td>\n",
       "      <td>22.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>25%</td>\n",
       "      <td>183.500000</td>\n",
       "      <td>2.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>4.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>0.337083</td>\n",
       "      <td>0.337842</td>\n",
       "      <td>0.520000</td>\n",
       "      <td>0.134950</td>\n",
       "      <td>315.500000</td>\n",
       "      <td>2497.000000</td>\n",
       "      <td>3152.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>50%</td>\n",
       "      <td>366.000000</td>\n",
       "      <td>3.000000</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>7.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>3.000000</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>0.498333</td>\n",
       "      <td>0.486733</td>\n",
       "      <td>0.626667</td>\n",
       "      <td>0.180975</td>\n",
       "      <td>713.000000</td>\n",
       "      <td>3662.000000</td>\n",
       "      <td>4548.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>75%</td>\n",
       "      <td>548.500000</td>\n",
       "      <td>3.000000</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>10.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>5.000000</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>2.000000</td>\n",
       "      <td>0.655417</td>\n",
       "      <td>0.608602</td>\n",
       "      <td>0.730209</td>\n",
       "      <td>0.233214</td>\n",
       "      <td>1096.000000</td>\n",
       "      <td>4776.500000</td>\n",
       "      <td>5956.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>max</td>\n",
       "      <td>731.000000</td>\n",
       "      <td>4.000000</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>12.000000</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>6.000000</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>3.000000</td>\n",
       "      <td>0.861667</td>\n",
       "      <td>0.840896</td>\n",
       "      <td>0.972500</td>\n",
       "      <td>0.507463</td>\n",
       "      <td>3410.000000</td>\n",
       "      <td>6946.000000</td>\n",
       "      <td>8714.000000</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "          instant      season          yr        mnth     holiday     weekday  \\\n",
       "count  731.000000  731.000000  731.000000  731.000000  731.000000  731.000000   \n",
       "mean   366.000000    2.496580    0.500684    6.519836    0.028728    2.997264   \n",
       "std    211.165812    1.110807    0.500342    3.451913    0.167155    2.004787   \n",
       "min      1.000000    1.000000    0.000000    1.000000    0.000000    0.000000   \n",
       "25%    183.500000    2.000000    0.000000    4.000000    0.000000    1.000000   \n",
       "50%    366.000000    3.000000    1.000000    7.000000    0.000000    3.000000   \n",
       "75%    548.500000    3.000000    1.000000   10.000000    0.000000    5.000000   \n",
       "max    731.000000    4.000000    1.000000   12.000000    1.000000    6.000000   \n",
       "\n",
       "       workingday  weathersit        temp       atemp         hum   windspeed  \\\n",
       "count  731.000000  731.000000  731.000000  731.000000  731.000000  731.000000   \n",
       "mean     0.683995    1.395349    0.495385    0.474354    0.627894    0.190486   \n",
       "std      0.465233    0.544894    0.183051    0.162961    0.142429    0.077498   \n",
       "min      0.000000    1.000000    0.059130    0.079070    0.000000    0.022392   \n",
       "25%      0.000000    1.000000    0.337083    0.337842    0.520000    0.134950   \n",
       "50%      1.000000    1.000000    0.498333    0.486733    0.626667    0.180975   \n",
       "75%      1.000000    2.000000    0.655417    0.608602    0.730209    0.233214   \n",
       "max      1.000000    3.000000    0.861667    0.840896    0.972500    0.507463   \n",
       "\n",
       "            casual   registered          cnt  \n",
       "count   731.000000   731.000000   731.000000  \n",
       "mean    848.176471  3656.172367  4504.348837  \n",
       "std     686.622488  1560.256377  1937.211452  \n",
       "min       2.000000    20.000000    22.000000  \n",
       "25%     315.500000  2497.000000  3152.000000  \n",
       "50%     713.000000  3662.000000  4548.000000  \n",
       "75%    1096.000000  4776.500000  5956.000000  \n",
       "max    3410.000000  6946.000000  8714.000000  "
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "train.describe()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 分离特征与响应值\n",
    "y_casual = train['casual']\n",
    "y_registered = train['registered']\n",
    "y_cnt = train['cnt']\n",
    "X = train.drop('instant', axis = 1)\n",
    "X = X.drop('dteday', axis = 1)\n",
    "X = X.drop('casual', axis = 1)\n",
    "X = X.drop('registered', axis = 1)\n",
    "X = X.drop('cnt', axis = 1)\n",
    "y_casual_log = np.log1p(y_casual)\n",
    "y_registered_log = np.log1p(y_registered)\n",
    "y_cnt_log = np.log1p(y_cnt)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 独热编码处理\n",
    "# 问题1:0/1值得列是否需要进行独热编码处理，分成两列\n",
    "# 编码列\n",
    "categorical_features = ['season','yr','mnth','holiday','weekday','workingday','weathersit']\n",
    "X_cat={}\n",
    "for cat in categorical_features:\n",
    "    X[cat].astype(\"object\")\n",
    "    X_cat[cat] = X[cat]\n",
    "    X_cat[cat] = pd.get_dummies(X_cat[cat], prefix=cat)\n",
    "    X = X.drop(cat, axis = 1)\n",
    "    \n",
    "feat_names = X.columns"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 去量纲\n",
    "from sklearn.preprocessing import StandardScaler\n",
    "\n",
    "ss_X = StandardScaler()\n",
    "ss_y_casual = StandardScaler()\n",
    "ss_y_registered = StandardScaler()\n",
    "ss_y_cnt = StandardScaler()\n",
    "ss_log_y_casual = StandardScaler()\n",
    "ss_log_y_registered = StandardScaler()\n",
    "ss_log_y_cnt = StandardScaler()\n",
    "\n",
    "X = ss_X.fit_transform(X)\n",
    "#y_casual = ss_y_casual.fit_transform(y_casual.values.reshape(-1, 1))\n",
    "#y_registered = ss_y_registered.fit_transform(y_registered.values.reshape(-1, 1))\n",
    "#y_cnt = ss_y_cnt.fit_transform(y_cnt.values.reshape(-1, 1))\n",
    "#y_casual_log = ss_log_y_casual.fit_transform(y_casual_log.values.reshape(-1, 1))\n",
    "#y_registered_log = ss_log_y_registered.fit_transform(y_registered_log.values.reshape(-1, 1))\n",
    "#y_cnt_log = ss_log_y_cnt.fit_transform(y_cnt_log.values.reshape(-1, 1))\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 保存预处理结果\n",
    "fe_data = pd.DataFrame(data = X, columns = feat_names, index = train.index)\n",
    "for cat in categorical_features:\n",
    "    fe_data = pd.concat([fe_data, X_cat[cat]], axis = 1, ignore_index=False)\n",
    "fe_data[\"casual\"] = y_casual\n",
    "fe_data[\"registered\"] = y_registered\n",
    "fe_data[\"cnt\"] = y_cnt\n",
    "fe_data[\"log_casual\"] = y_casual_log\n",
    "fe_data[\"log_registered\"] = y_registered_log\n",
    "fe_data[\"log_cnt\"] = y_cnt_log\n",
    "fe_data.to_csv('FE_day.csv', index=False)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>temp</th>\n",
       "      <th>atemp</th>\n",
       "      <th>hum</th>\n",
       "      <th>windspeed</th>\n",
       "      <th>season_1</th>\n",
       "      <th>season_2</th>\n",
       "      <th>season_3</th>\n",
       "      <th>season_4</th>\n",
       "      <th>yr_0</th>\n",
       "      <th>yr_1</th>\n",
       "      <th>...</th>\n",
       "      <th>workingday_1</th>\n",
       "      <th>weathersit_1</th>\n",
       "      <th>weathersit_2</th>\n",
       "      <th>weathersit_3</th>\n",
       "      <th>casual</th>\n",
       "      <th>registered</th>\n",
       "      <th>cnt</th>\n",
       "      <th>log_casual</th>\n",
       "      <th>log_registered</th>\n",
       "      <th>log_cnt</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <td>0</td>\n",
       "      <td>-0.826662</td>\n",
       "      <td>-0.679946</td>\n",
       "      <td>1.250171</td>\n",
       "      <td>-0.387892</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>...</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>331</td>\n",
       "      <td>654</td>\n",
       "      <td>985</td>\n",
       "      <td>5.805135</td>\n",
       "      <td>6.484635</td>\n",
       "      <td>6.893656</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>1</td>\n",
       "      <td>-0.721095</td>\n",
       "      <td>-0.740652</td>\n",
       "      <td>0.479113</td>\n",
       "      <td>0.749602</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>...</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>131</td>\n",
       "      <td>670</td>\n",
       "      <td>801</td>\n",
       "      <td>4.882802</td>\n",
       "      <td>6.508769</td>\n",
       "      <td>6.687109</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>2</td>\n",
       "      <td>-1.634657</td>\n",
       "      <td>-1.749767</td>\n",
       "      <td>-1.339274</td>\n",
       "      <td>0.746632</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>...</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>120</td>\n",
       "      <td>1229</td>\n",
       "      <td>1349</td>\n",
       "      <td>4.795791</td>\n",
       "      <td>7.114769</td>\n",
       "      <td>7.207860</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>3</td>\n",
       "      <td>-1.614780</td>\n",
       "      <td>-1.610270</td>\n",
       "      <td>-0.263182</td>\n",
       "      <td>-0.389829</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>...</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>108</td>\n",
       "      <td>1454</td>\n",
       "      <td>1562</td>\n",
       "      <td>4.691348</td>\n",
       "      <td>7.282761</td>\n",
       "      <td>7.354362</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>4</td>\n",
       "      <td>-1.467414</td>\n",
       "      <td>-1.504971</td>\n",
       "      <td>-1.341494</td>\n",
       "      <td>-0.046307</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>...</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>82</td>\n",
       "      <td>1518</td>\n",
       "      <td>1600</td>\n",
       "      <td>4.418841</td>\n",
       "      <td>7.325808</td>\n",
       "      <td>7.378384</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>5 rows × 42 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "       temp     atemp       hum  windspeed  season_1  season_2  season_3  \\\n",
       "0 -0.826662 -0.679946  1.250171  -0.387892         1         0         0   \n",
       "1 -0.721095 -0.740652  0.479113   0.749602         1         0         0   \n",
       "2 -1.634657 -1.749767 -1.339274   0.746632         1         0         0   \n",
       "3 -1.614780 -1.610270 -0.263182  -0.389829         1         0         0   \n",
       "4 -1.467414 -1.504971 -1.341494  -0.046307         1         0         0   \n",
       "\n",
       "   season_4  yr_0  yr_1  ...  workingday_1  weathersit_1  weathersit_2  \\\n",
       "0         0     1     0  ...             0             0             1   \n",
       "1         0     1     0  ...             0             0             1   \n",
       "2         0     1     0  ...             1             1             0   \n",
       "3         0     1     0  ...             1             1             0   \n",
       "4         0     1     0  ...             1             1             0   \n",
       "\n",
       "   weathersit_3  casual  registered   cnt  log_casual  log_registered  \\\n",
       "0             0     331         654   985    5.805135        6.484635   \n",
       "1             0     131         670   801    4.882802        6.508769   \n",
       "2             0     120        1229  1349    4.795791        7.114769   \n",
       "3             0     108        1454  1562    4.691348        7.282761   \n",
       "4             0      82        1518  1600    4.418841        7.325808   \n",
       "\n",
       "    log_cnt  \n",
       "0  6.893656  \n",
       "1  6.687109  \n",
       "2  7.207860  \n",
       "3  7.354362  \n",
       "4  7.378384  \n",
       "\n",
       "[5 rows x 42 columns]"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "fe_data.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>temp</th>\n",
       "      <th>atemp</th>\n",
       "      <th>hum</th>\n",
       "      <th>windspeed</th>\n",
       "      <th>season_1</th>\n",
       "      <th>season_2</th>\n",
       "      <th>season_3</th>\n",
       "      <th>season_4</th>\n",
       "      <th>yr_0</th>\n",
       "      <th>yr_1</th>\n",
       "      <th>...</th>\n",
       "      <th>workingday_1</th>\n",
       "      <th>weathersit_1</th>\n",
       "      <th>weathersit_2</th>\n",
       "      <th>weathersit_3</th>\n",
       "      <th>casual</th>\n",
       "      <th>registered</th>\n",
       "      <th>cnt</th>\n",
       "      <th>log_casual</th>\n",
       "      <th>log_registered</th>\n",
       "      <th>log_cnt</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <td>0</td>\n",
       "      <td>-0.826662</td>\n",
       "      <td>-0.679946</td>\n",
       "      <td>1.250171</td>\n",
       "      <td>-0.387892</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>...</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>331</td>\n",
       "      <td>654</td>\n",
       "      <td>985</td>\n",
       "      <td>5.805135</td>\n",
       "      <td>6.484635</td>\n",
       "      <td>6.893656</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>1</td>\n",
       "      <td>-0.721095</td>\n",
       "      <td>-0.740652</td>\n",
       "      <td>0.479113</td>\n",
       "      <td>0.749602</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>...</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>131</td>\n",
       "      <td>670</td>\n",
       "      <td>801</td>\n",
       "      <td>4.882802</td>\n",
       "      <td>6.508769</td>\n",
       "      <td>6.687109</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>2</td>\n",
       "      <td>-1.634657</td>\n",
       "      <td>-1.749767</td>\n",
       "      <td>-1.339274</td>\n",
       "      <td>0.746632</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>...</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>120</td>\n",
       "      <td>1229</td>\n",
       "      <td>1349</td>\n",
       "      <td>4.795791</td>\n",
       "      <td>7.114769</td>\n",
       "      <td>7.207860</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>3</td>\n",
       "      <td>-1.614780</td>\n",
       "      <td>-1.610270</td>\n",
       "      <td>-0.263182</td>\n",
       "      <td>-0.389829</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>...</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>108</td>\n",
       "      <td>1454</td>\n",
       "      <td>1562</td>\n",
       "      <td>4.691348</td>\n",
       "      <td>7.282761</td>\n",
       "      <td>7.354362</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>4</td>\n",
       "      <td>-1.467414</td>\n",
       "      <td>-1.504971</td>\n",
       "      <td>-1.341494</td>\n",
       "      <td>-0.046307</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>...</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>82</td>\n",
       "      <td>1518</td>\n",
       "      <td>1600</td>\n",
       "      <td>4.418841</td>\n",
       "      <td>7.325808</td>\n",
       "      <td>7.378384</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>5 rows × 42 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "       temp     atemp       hum  windspeed  season_1  season_2  season_3  \\\n",
       "0 -0.826662 -0.679946  1.250171  -0.387892         1         0         0   \n",
       "1 -0.721095 -0.740652  0.479113   0.749602         1         0         0   \n",
       "2 -1.634657 -1.749767 -1.339274   0.746632         1         0         0   \n",
       "3 -1.614780 -1.610270 -0.263182  -0.389829         1         0         0   \n",
       "4 -1.467414 -1.504971 -1.341494  -0.046307         1         0         0   \n",
       "\n",
       "   season_4  yr_0  yr_1  ...  workingday_1  weathersit_1  weathersit_2  \\\n",
       "0         0     1     0  ...             0             0             1   \n",
       "1         0     1     0  ...             0             0             1   \n",
       "2         0     1     0  ...             1             1             0   \n",
       "3         0     1     0  ...             1             1             0   \n",
       "4         0     1     0  ...             1             1             0   \n",
       "\n",
       "   weathersit_3  casual  registered   cnt  log_casual  log_registered  \\\n",
       "0             0     331         654   985    5.805135        6.484635   \n",
       "1             0     131         670   801    4.882802        6.508769   \n",
       "2             0     120        1229  1349    4.795791        7.114769   \n",
       "3             0     108        1454  1562    4.691348        7.282761   \n",
       "4             0      82        1518  1600    4.418841        7.325808   \n",
       "\n",
       "    log_cnt  \n",
       "0  6.893656  \n",
       "1  6.687109  \n",
       "2  7.207860  \n",
       "3  7.354362  \n",
       "4  7.378384  \n",
       "\n",
       "[5 rows x 42 columns]"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 加载数据\n",
    "df = pd.read_csv(\"FE_day.csv\")\n",
    "df.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 分离特征与输出\n",
    "y_casual = df[\"casual\"]\n",
    "y_registered = df[\"registered\"]\n",
    "y_cnt = df[\"cnt\"]\n",
    "log_y_casual = df[\"log_casual\"]\n",
    "log_y_registered = df[\"log_registered\"]\n",
    "log_y_cnt = df[\"log_cnt\"]\n",
    "X = df.drop([\"casual\", \"registered\", \"cnt\", \"log_casual\", \"log_registered\", \"log_cnt\"], axis = 1)\n",
    "feat_names = X.columns\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 分割训练集与测试集\n",
    "# 有多个y，如何split\n",
    "# 有多个编码字段，如何split\n",
    "from sklearn.model_selection import train_test_split\n",
    "X_train, X_test, y_train, y_test = train_test_split(X, y_cnt, random_state=33, test_size=0.2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [],
   "source": [
    "def linear_scatter(y_train, y_train_pred, y_test, y_test_pred):\n",
    "    plt.scatter(y_train, y_train_pred, marker='o', color='green', label='train')\n",
    "    plt.scatter(y_test, y_test_pred, marker='*', color='blue', label='test')\n",
    "    plt.plot([-3, 3], [-3, 3], '--r')\n",
    "    plt.axis('tight')\n",
    "    plt.xlabel(\"True price\")\n",
    "    plt.ylabel(\"Predicted price\")\n",
    "    plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [],
   "source": [
    "from sklearn.metrics import r2_score\n",
    "from sklearn.metrics import mean_squared_error\n",
    "def rmse(y_true, y_pred):\n",
    "    mse = mean_squared_error(y_true, y_pred)\n",
    "    return mse**0.5"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>columns</th>\n",
       "      <th>coef</th>\n",
       "      <th>coef_abs</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <td>35</td>\n",
       "      <td>weathersit_3</td>\n",
       "      <td>-1317.780691</td>\n",
       "      <td>1317.780691</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>9</td>\n",
       "      <td>yr_1</td>\n",
       "      <td>1009.546277</td>\n",
       "      <td>1009.546277</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>8</td>\n",
       "      <td>yr_0</td>\n",
       "      <td>-1009.546277</td>\n",
       "      <td>1009.546277</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>33</td>\n",
       "      <td>weathersit_1</td>\n",
       "      <td>903.819561</td>\n",
       "      <td>903.819561</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>7</td>\n",
       "      <td>season_4</td>\n",
       "      <td>839.987713</td>\n",
       "      <td>839.987713</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>4</td>\n",
       "      <td>season_1</td>\n",
       "      <td>-778.861271</td>\n",
       "      <td>778.861271</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>18</td>\n",
       "      <td>mnth_9</td>\n",
       "      <td>776.592967</td>\n",
       "      <td>776.592967</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>21</td>\n",
       "      <td>mnth_12</td>\n",
       "      <td>-584.113711</td>\n",
       "      <td>584.113711</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>0</td>\n",
       "      <td>temp</td>\n",
       "      <td>576.826916</td>\n",
       "      <td>576.826916</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>20</td>\n",
       "      <td>mnth_11</td>\n",
       "      <td>-563.610563</td>\n",
       "      <td>563.610563</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>34</td>\n",
       "      <td>weathersit_2</td>\n",
       "      <td>413.961130</td>\n",
       "      <td>413.961130</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>10</td>\n",
       "      <td>mnth_1</td>\n",
       "      <td>-350.267803</td>\n",
       "      <td>350.267803</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>14</td>\n",
       "      <td>mnth_5</td>\n",
       "      <td>335.218767</td>\n",
       "      <td>335.218767</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>15</td>\n",
       "      <td>mnth_6</td>\n",
       "      <td>307.860502</td>\n",
       "      <td>307.860502</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>16</td>\n",
       "      <td>mnth_7</td>\n",
       "      <td>-293.012896</td>\n",
       "      <td>293.012896</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>11</td>\n",
       "      <td>mnth_2</td>\n",
       "      <td>-275.895678</td>\n",
       "      <td>275.895678</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>1</td>\n",
       "      <td>atemp</td>\n",
       "      <td>234.417136</td>\n",
       "      <td>234.417136</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>30</td>\n",
       "      <td>weekday_6</td>\n",
       "      <td>231.940652</td>\n",
       "      <td>231.940652</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>17</td>\n",
       "      <td>mnth_8</td>\n",
       "      <td>221.598038</td>\n",
       "      <td>221.598038</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>25</td>\n",
       "      <td>weekday_1</td>\n",
       "      <td>-200.050530</td>\n",
       "      <td>200.050530</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>24</td>\n",
       "      <td>weekday_0</td>\n",
       "      <td>-199.938408</td>\n",
       "      <td>199.938408</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>2</td>\n",
       "      <td>hum</td>\n",
       "      <td>-199.246532</td>\n",
       "      <td>199.246532</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>12</td>\n",
       "      <td>mnth_3</td>\n",
       "      <td>194.398815</td>\n",
       "      <td>194.398815</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>3</td>\n",
       "      <td>windspeed</td>\n",
       "      <td>-191.482356</td>\n",
       "      <td>191.482356</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>19</td>\n",
       "      <td>mnth_10</td>\n",
       "      <td>182.474431</td>\n",
       "      <td>182.474431</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>6</td>\n",
       "      <td>season_3</td>\n",
       "      <td>-137.876425</td>\n",
       "      <td>137.876425</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>23</td>\n",
       "      <td>holiday_1</td>\n",
       "      <td>-134.023963</td>\n",
       "      <td>134.023963</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>22</td>\n",
       "      <td>holiday_0</td>\n",
       "      <td>134.023963</td>\n",
       "      <td>134.023963</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>31</td>\n",
       "      <td>workingday_0</td>\n",
       "      <td>-102.021720</td>\n",
       "      <td>102.021720</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>32</td>\n",
       "      <td>workingday_1</td>\n",
       "      <td>102.021720</td>\n",
       "      <td>102.021720</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>29</td>\n",
       "      <td>weekday_5</td>\n",
       "      <td>77.954738</td>\n",
       "      <td>77.954738</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>5</td>\n",
       "      <td>season_2</td>\n",
       "      <td>76.749983</td>\n",
       "      <td>76.749983</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>27</td>\n",
       "      <td>weekday_3</td>\n",
       "      <td>67.132109</td>\n",
       "      <td>67.132109</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>28</td>\n",
       "      <td>weekday_4</td>\n",
       "      <td>55.573920</td>\n",
       "      <td>55.573920</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>13</td>\n",
       "      <td>mnth_4</td>\n",
       "      <td>48.757131</td>\n",
       "      <td>48.757131</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>26</td>\n",
       "      <td>weekday_2</td>\n",
       "      <td>-32.612480</td>\n",
       "      <td>32.612480</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "         columns         coef     coef_abs\n",
       "35  weathersit_3 -1317.780691  1317.780691\n",
       "9           yr_1  1009.546277  1009.546277\n",
       "8           yr_0 -1009.546277  1009.546277\n",
       "33  weathersit_1   903.819561   903.819561\n",
       "7       season_4   839.987713   839.987713\n",
       "4       season_1  -778.861271   778.861271\n",
       "18        mnth_9   776.592967   776.592967\n",
       "21       mnth_12  -584.113711   584.113711\n",
       "0           temp   576.826916   576.826916\n",
       "20       mnth_11  -563.610563   563.610563\n",
       "34  weathersit_2   413.961130   413.961130\n",
       "10        mnth_1  -350.267803   350.267803\n",
       "14        mnth_5   335.218767   335.218767\n",
       "15        mnth_6   307.860502   307.860502\n",
       "16        mnth_7  -293.012896   293.012896\n",
       "11        mnth_2  -275.895678   275.895678\n",
       "1          atemp   234.417136   234.417136\n",
       "30     weekday_6   231.940652   231.940652\n",
       "17        mnth_8   221.598038   221.598038\n",
       "25     weekday_1  -200.050530   200.050530\n",
       "24     weekday_0  -199.938408   199.938408\n",
       "2            hum  -199.246532   199.246532\n",
       "12        mnth_3   194.398815   194.398815\n",
       "3      windspeed  -191.482356   191.482356\n",
       "19       mnth_10   182.474431   182.474431\n",
       "6       season_3  -137.876425   137.876425\n",
       "23     holiday_1  -134.023963   134.023963\n",
       "22     holiday_0   134.023963   134.023963\n",
       "31  workingday_0  -102.021720   102.021720\n",
       "32  workingday_1   102.021720   102.021720\n",
       "29     weekday_5    77.954738    77.954738\n",
       "5       season_2    76.749983    76.749983\n",
       "27     weekday_3    67.132109    67.132109\n",
       "28     weekday_4    55.573920    55.573920\n",
       "13        mnth_4    48.757131    48.757131\n",
       "26     weekday_2   -32.612480    32.612480"
      ]
     },
     "execution_count": 16,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 线性回归\n",
    "from sklearn.linear_model import LinearRegression\n",
    "lr = LinearRegression()\n",
    "lr.fit(X_train, y_train)\n",
    "y_test_pred_lr = lr.predict(X_test)\n",
    "y_train_pred_lr = lr.predict(X_train)\n",
    "fs = pd.DataFrame({\"columns\":list(feat_names), \"coef\":list((lr.coef_.T)), \"coef_abs\": list(abs(lr.coef_.T))})\n",
    "fs.sort_values(by=['coef_abs'],ascending=False)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "3658.2983072661414"
      ]
     },
     "execution_count": 17,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "lr.intercept_"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "The rmse score of LinearRegression on test is 814.8548088108182\n",
      "The rmse score of LinearRegression on train is 745.1191334033962\n"
     ]
    }
   ],
   "source": [
    "print('The rmse score of LinearRegression on test is', rmse(y_test, y_test_pred_lr))\n",
    "print('The rmse score of LinearRegression on train is', rmse(y_train, y_train_pred_lr))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>columns</th>\n",
       "      <th>coef</th>\n",
       "      <th>coef_abs</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <td>35</td>\n",
       "      <td>weathersit_3</td>\n",
       "      <td>-1251.771868</td>\n",
       "      <td>1251.771868</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>9</td>\n",
       "      <td>yr_1</td>\n",
       "      <td>1004.746949</td>\n",
       "      <td>1004.746949</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>8</td>\n",
       "      <td>yr_0</td>\n",
       "      <td>-1004.746949</td>\n",
       "      <td>1004.746949</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>33</td>\n",
       "      <td>weathersit_1</td>\n",
       "      <td>865.847556</td>\n",
       "      <td>865.847556</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>7</td>\n",
       "      <td>season_4</td>\n",
       "      <td>784.483535</td>\n",
       "      <td>784.483535</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>4</td>\n",
       "      <td>season_1</td>\n",
       "      <td>-777.841154</td>\n",
       "      <td>777.841154</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>18</td>\n",
       "      <td>mnth_9</td>\n",
       "      <td>746.334275</td>\n",
       "      <td>746.334275</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>0</td>\n",
       "      <td>temp</td>\n",
       "      <td>568.576505</td>\n",
       "      <td>568.576505</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>21</td>\n",
       "      <td>mnth_12</td>\n",
       "      <td>-514.962029</td>\n",
       "      <td>514.962029</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>20</td>\n",
       "      <td>mnth_11</td>\n",
       "      <td>-484.258440</td>\n",
       "      <td>484.258440</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>34</td>\n",
       "      <td>weathersit_2</td>\n",
       "      <td>385.924312</td>\n",
       "      <td>385.924312</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>16</td>\n",
       "      <td>mnth_7</td>\n",
       "      <td>-337.132230</td>\n",
       "      <td>337.132230</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>10</td>\n",
       "      <td>mnth_1</td>\n",
       "      <td>-315.386304</td>\n",
       "      <td>315.386304</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>14</td>\n",
       "      <td>mnth_5</td>\n",
       "      <td>288.470241</td>\n",
       "      <td>288.470241</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>1</td>\n",
       "      <td>atemp</td>\n",
       "      <td>264.492541</td>\n",
       "      <td>264.492541</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>15</td>\n",
       "      <td>mnth_6</td>\n",
       "      <td>252.512074</td>\n",
       "      <td>252.512074</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>11</td>\n",
       "      <td>mnth_2</td>\n",
       "      <td>-248.472574</td>\n",
       "      <td>248.472574</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>19</td>\n",
       "      <td>mnth_10</td>\n",
       "      <td>229.310210</td>\n",
       "      <td>229.310210</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>30</td>\n",
       "      <td>weekday_6</td>\n",
       "      <td>227.004268</td>\n",
       "      <td>227.004268</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>2</td>\n",
       "      <td>hum</td>\n",
       "      <td>-207.726091</td>\n",
       "      <td>207.726091</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>3</td>\n",
       "      <td>windspeed</td>\n",
       "      <td>-195.511521</td>\n",
       "      <td>195.511521</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>25</td>\n",
       "      <td>weekday_1</td>\n",
       "      <td>-194.561832</td>\n",
       "      <td>194.561832</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>24</td>\n",
       "      <td>weekday_0</td>\n",
       "      <td>-193.998877</td>\n",
       "      <td>193.998877</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>12</td>\n",
       "      <td>mnth_3</td>\n",
       "      <td>189.774360</td>\n",
       "      <td>189.774360</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>17</td>\n",
       "      <td>mnth_8</td>\n",
       "      <td>178.838778</td>\n",
       "      <td>178.838778</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>22</td>\n",
       "      <td>holiday_0</td>\n",
       "      <td>134.687718</td>\n",
       "      <td>134.687718</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>23</td>\n",
       "      <td>holiday_1</td>\n",
       "      <td>-134.687718</td>\n",
       "      <td>134.687718</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>6</td>\n",
       "      <td>season_3</td>\n",
       "      <td>-118.186023</td>\n",
       "      <td>118.186023</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>5</td>\n",
       "      <td>season_2</td>\n",
       "      <td>111.543642</td>\n",
       "      <td>111.543642</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>31</td>\n",
       "      <td>workingday_0</td>\n",
       "      <td>-101.682326</td>\n",
       "      <td>101.682326</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>32</td>\n",
       "      <td>workingday_1</td>\n",
       "      <td>101.682326</td>\n",
       "      <td>101.682326</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>29</td>\n",
       "      <td>weekday_5</td>\n",
       "      <td>79.048592</td>\n",
       "      <td>79.048592</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>27</td>\n",
       "      <td>weekday_3</td>\n",
       "      <td>62.929073</td>\n",
       "      <td>62.929073</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>28</td>\n",
       "      <td>weekday_4</td>\n",
       "      <td>51.679796</td>\n",
       "      <td>51.679796</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>26</td>\n",
       "      <td>weekday_2</td>\n",
       "      <td>-32.101019</td>\n",
       "      <td>32.101019</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>13</td>\n",
       "      <td>mnth_4</td>\n",
       "      <td>14.971638</td>\n",
       "      <td>14.971638</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "         columns         coef     coef_abs\n",
       "35  weathersit_3 -1251.771868  1251.771868\n",
       "9           yr_1  1004.746949  1004.746949\n",
       "8           yr_0 -1004.746949  1004.746949\n",
       "33  weathersit_1   865.847556   865.847556\n",
       "7       season_4   784.483535   784.483535\n",
       "4       season_1  -777.841154   777.841154\n",
       "18        mnth_9   746.334275   746.334275\n",
       "0           temp   568.576505   568.576505\n",
       "21       mnth_12  -514.962029   514.962029\n",
       "20       mnth_11  -484.258440   484.258440\n",
       "34  weathersit_2   385.924312   385.924312\n",
       "16        mnth_7  -337.132230   337.132230\n",
       "10        mnth_1  -315.386304   315.386304\n",
       "14        mnth_5   288.470241   288.470241\n",
       "1          atemp   264.492541   264.492541\n",
       "15        mnth_6   252.512074   252.512074\n",
       "11        mnth_2  -248.472574   248.472574\n",
       "19       mnth_10   229.310210   229.310210\n",
       "30     weekday_6   227.004268   227.004268\n",
       "2            hum  -207.726091   207.726091\n",
       "3      windspeed  -195.511521   195.511521\n",
       "25     weekday_1  -194.561832   194.561832\n",
       "24     weekday_0  -193.998877   193.998877\n",
       "12        mnth_3   189.774360   189.774360\n",
       "17        mnth_8   178.838778   178.838778\n",
       "22     holiday_0   134.687718   134.687718\n",
       "23     holiday_1  -134.687718   134.687718\n",
       "6       season_3  -118.186023   118.186023\n",
       "5       season_2   111.543642   111.543642\n",
       "31  workingday_0  -101.682326   101.682326\n",
       "32  workingday_1   101.682326   101.682326\n",
       "29     weekday_5    79.048592    79.048592\n",
       "27     weekday_3    62.929073    62.929073\n",
       "28     weekday_4    51.679796    51.679796\n",
       "26     weekday_2   -32.101019    32.101019\n",
       "13        mnth_4    14.971638    14.971638"
      ]
     },
     "execution_count": 19,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 岭回归\n",
    "from sklearn.linear_model import  RidgeCV\n",
    "alphas = [ 1e-5,1e-4,1e-3,1e-2,1e-1,1,1e1,1e2,1e3,1e4,1e5]\n",
    "#ridge = RidgeCV(alphas=alphas, store_cv_values=True)  \n",
    "ridge = RidgeCV()  \n",
    "ridge.fit(X_train, y_train)    \n",
    "y_test_pred_ridge = ridge.predict(X_test)\n",
    "y_train_pred_ridge = ridge.predict(X_train)\n",
    "fs_ridge = pd.DataFrame({\"columns\":list(feat_names), \"coef\":list((ridge.coef_.T)), \"coef_abs\": list(abs(ridge.coef_.T))})\n",
    "fs_ridge.sort_values(by=['coef_abs'],ascending=False)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "3689.2982041456803"
      ]
     },
     "execution_count": 20,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "ridge.intercept_"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "The rmse score of RidgeCV on test is 807.9318870849086\n",
      "The rmse score of RidgeCV on train is 745.4659213245671\n",
      "alpha is: 1.0\n"
     ]
    }
   ],
   "source": [
    "print('The rmse score of RidgeCV on test is', rmse(y_test, y_test_pred_ridge))\n",
    "print('The rmse score of RidgeCV on train is', rmse(y_train, y_train_pred_ridge))\n",
    "print('alpha is:', ridge.alpha_)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>columns</th>\n",
       "      <th>coef</th>\n",
       "      <th>coef_abs</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <td>8</td>\n",
       "      <td>yr_0</td>\n",
       "      <td>-1.986959e+03</td>\n",
       "      <td>1.986959e+03</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>35</td>\n",
       "      <td>weathersit_3</td>\n",
       "      <td>-1.505226e+03</td>\n",
       "      <td>1.505226e+03</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>4</td>\n",
       "      <td>season_1</td>\n",
       "      <td>-1.060390e+03</td>\n",
       "      <td>1.060390e+03</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>0</td>\n",
       "      <td>temp</td>\n",
       "      <td>7.125340e+02</td>\n",
       "      <td>7.125340e+02</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>18</td>\n",
       "      <td>mnth_9</td>\n",
       "      <td>6.169576e+02</td>\n",
       "      <td>6.169576e+02</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>16</td>\n",
       "      <td>mnth_7</td>\n",
       "      <td>-4.849027e+02</td>\n",
       "      <td>4.849027e+02</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>33</td>\n",
       "      <td>weathersit_1</td>\n",
       "      <td>4.526126e+02</td>\n",
       "      <td>4.526126e+02</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>7</td>\n",
       "      <td>season_4</td>\n",
       "      <td>4.302854e+02</td>\n",
       "      <td>4.302854e+02</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>19</td>\n",
       "      <td>mnth_10</td>\n",
       "      <td>3.500060e+02</td>\n",
       "      <td>3.500060e+02</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>24</td>\n",
       "      <td>weekday_0</td>\n",
       "      <td>-3.353495e+02</td>\n",
       "      <td>3.353495e+02</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>22</td>\n",
       "      <td>holiday_0</td>\n",
       "      <td>2.762207e+02</td>\n",
       "      <td>2.762207e+02</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>12</td>\n",
       "      <td>mnth_3</td>\n",
       "      <td>2.441109e+02</td>\n",
       "      <td>2.441109e+02</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>2</td>\n",
       "      <td>hum</td>\n",
       "      <td>-2.187887e+02</td>\n",
       "      <td>2.187887e+02</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>21</td>\n",
       "      <td>mnth_12</td>\n",
       "      <td>-2.117084e+02</td>\n",
       "      <td>2.117084e+02</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>1</td>\n",
       "      <td>atemp</td>\n",
       "      <td>2.086699e+02</td>\n",
       "      <td>2.086699e+02</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>6</td>\n",
       "      <td>season_3</td>\n",
       "      <td>-2.025993e+02</td>\n",
       "      <td>2.025993e+02</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>3</td>\n",
       "      <td>windspeed</td>\n",
       "      <td>-1.987806e+02</td>\n",
       "      <td>1.987806e+02</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>25</td>\n",
       "      <td>weekday_1</td>\n",
       "      <td>-1.978890e+02</td>\n",
       "      <td>1.978890e+02</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>20</td>\n",
       "      <td>mnth_11</td>\n",
       "      <td>-1.836343e+02</td>\n",
       "      <td>1.836343e+02</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>14</td>\n",
       "      <td>mnth_5</td>\n",
       "      <td>1.424687e+02</td>\n",
       "      <td>1.424687e+02</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>15</td>\n",
       "      <td>mnth_6</td>\n",
       "      <td>4.323616e+01</td>\n",
       "      <td>4.323616e+01</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>31</td>\n",
       "      <td>workingday_0</td>\n",
       "      <td>-4.101820e+01</td>\n",
       "      <td>4.101820e+01</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>10</td>\n",
       "      <td>mnth_1</td>\n",
       "      <td>-2.981205e+01</td>\n",
       "      <td>2.981205e+01</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>26</td>\n",
       "      <td>weekday_2</td>\n",
       "      <td>-2.479186e+01</td>\n",
       "      <td>2.479186e+01</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>29</td>\n",
       "      <td>weekday_5</td>\n",
       "      <td>1.199215e+01</td>\n",
       "      <td>1.199215e+01</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>23</td>\n",
       "      <td>holiday_1</td>\n",
       "      <td>-2.178099e-12</td>\n",
       "      <td>2.178099e-12</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>9</td>\n",
       "      <td>yr_1</td>\n",
       "      <td>4.117257e-13</td>\n",
       "      <td>4.117257e-13</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>32</td>\n",
       "      <td>workingday_1</td>\n",
       "      <td>2.912657e-14</td>\n",
       "      <td>2.912657e-14</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>11</td>\n",
       "      <td>mnth_2</td>\n",
       "      <td>-0.000000e+00</td>\n",
       "      <td>0.000000e+00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>13</td>\n",
       "      <td>mnth_4</td>\n",
       "      <td>-0.000000e+00</td>\n",
       "      <td>0.000000e+00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>27</td>\n",
       "      <td>weekday_3</td>\n",
       "      <td>0.000000e+00</td>\n",
       "      <td>0.000000e+00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>28</td>\n",
       "      <td>weekday_4</td>\n",
       "      <td>0.000000e+00</td>\n",
       "      <td>0.000000e+00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>30</td>\n",
       "      <td>weekday_6</td>\n",
       "      <td>0.000000e+00</td>\n",
       "      <td>0.000000e+00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>5</td>\n",
       "      <td>season_2</td>\n",
       "      <td>0.000000e+00</td>\n",
       "      <td>0.000000e+00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>34</td>\n",
       "      <td>weathersit_2</td>\n",
       "      <td>-0.000000e+00</td>\n",
       "      <td>0.000000e+00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>17</td>\n",
       "      <td>mnth_8</td>\n",
       "      <td>0.000000e+00</td>\n",
       "      <td>0.000000e+00</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "         columns          coef      coef_abs\n",
       "8           yr_0 -1.986959e+03  1.986959e+03\n",
       "35  weathersit_3 -1.505226e+03  1.505226e+03\n",
       "4       season_1 -1.060390e+03  1.060390e+03\n",
       "0           temp  7.125340e+02  7.125340e+02\n",
       "18        mnth_9  6.169576e+02  6.169576e+02\n",
       "16        mnth_7 -4.849027e+02  4.849027e+02\n",
       "33  weathersit_1  4.526126e+02  4.526126e+02\n",
       "7       season_4  4.302854e+02  4.302854e+02\n",
       "19       mnth_10  3.500060e+02  3.500060e+02\n",
       "24     weekday_0 -3.353495e+02  3.353495e+02\n",
       "22     holiday_0  2.762207e+02  2.762207e+02\n",
       "12        mnth_3  2.441109e+02  2.441109e+02\n",
       "2            hum -2.187887e+02  2.187887e+02\n",
       "21       mnth_12 -2.117084e+02  2.117084e+02\n",
       "1          atemp  2.086699e+02  2.086699e+02\n",
       "6       season_3 -2.025993e+02  2.025993e+02\n",
       "3      windspeed -1.987806e+02  1.987806e+02\n",
       "25     weekday_1 -1.978890e+02  1.978890e+02\n",
       "20       mnth_11 -1.836343e+02  1.836343e+02\n",
       "14        mnth_5  1.424687e+02  1.424687e+02\n",
       "15        mnth_6  4.323616e+01  4.323616e+01\n",
       "31  workingday_0 -4.101820e+01  4.101820e+01\n",
       "10        mnth_1 -2.981205e+01  2.981205e+01\n",
       "26     weekday_2 -2.479186e+01  2.479186e+01\n",
       "29     weekday_5  1.199215e+01  1.199215e+01\n",
       "23     holiday_1 -2.178099e-12  2.178099e-12\n",
       "9           yr_1  4.117257e-13  4.117257e-13\n",
       "32  workingday_1  2.912657e-14  2.912657e-14\n",
       "11        mnth_2 -0.000000e+00  0.000000e+00\n",
       "13        mnth_4 -0.000000e+00  0.000000e+00\n",
       "27     weekday_3  0.000000e+00  0.000000e+00\n",
       "28     weekday_4  0.000000e+00  0.000000e+00\n",
       "30     weekday_6  0.000000e+00  0.000000e+00\n",
       "5       season_2  0.000000e+00  0.000000e+00\n",
       "34  weathersit_2 -0.000000e+00  0.000000e+00\n",
       "17        mnth_8  0.000000e+00  0.000000e+00"
      ]
     },
     "execution_count": 22,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# Lasso回归\n",
    "from sklearn.linear_model import  LassoCV\n",
    "alphas = [ 1e-5,1e-4,1e-3,1e-2,1e-1,1,1e1,1e2,1e3,1e4,1e5]\n",
    "#lasso = LassoCV(alphas=alphas)\n",
    "lasso = LassoCV(cv=3)\n",
    "lasso.fit(X_train, y_train)    \n",
    "y_test_pred_lasso = lasso.predict(X_test)\n",
    "y_train_pred_lasso = lasso.predict(X_train)\n",
    "fs_lasso = pd.DataFrame({\"columns\":list(feat_names), \"coef\":list((lasso.coef_.T)), \"coef_abs\": list(abs(lasso.coef_.T))})\n",
    "fs_lasso.sort_values(by=['coef_abs'],ascending=False)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "5236.128903703764"
      ]
     },
     "execution_count": 23,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "lasso.intercept_"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "The rmse score of LassoCV on test is 792.6973921123254\n",
      "The rmse score of LassoCV on train is 752.6149170502838\n",
      "alpha is: 5.214194297561414\n"
     ]
    }
   ],
   "source": [
    "print('The rmse score of LassoCV on test is', rmse(y_test, y_test_pred_lasso))\n",
    "print('The rmse score of LassoCV on train is', rmse(y_train, y_train_pred_lasso))\n",
    "print('alpha is:', lasso.alpha_)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "根据RMSE指标定义，指标值越小越好，从数据看，Lasso回归获得了比较好的测试数据指标，而训练数据指标略低，但训练指标和测试指标更接近，说明其更接近真实情况；而另外两种方法过拟合现象要比Lasso回归高一些；\n",
    "\n",
    "从特征系数看，排在前几位与骑行量相关角度的因素是：天气、年份、季节、温度，而湿度、星期几、是否节假日这对骑行量影响较小；不同模型得到的权重系数略有不同，Lasso模型可以得到稀疏解，更有利于排除一些维度"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>temp</th>\n",
       "      <th>atemp</th>\n",
       "      <th>hum</th>\n",
       "      <th>windspeed</th>\n",
       "      <th>season_1</th>\n",
       "      <th>season_2</th>\n",
       "      <th>season_3</th>\n",
       "      <th>season_4</th>\n",
       "      <th>yr_0</th>\n",
       "      <th>yr_1</th>\n",
       "      <th>...</th>\n",
       "      <th>weekday_2</th>\n",
       "      <th>weekday_3</th>\n",
       "      <th>weekday_4</th>\n",
       "      <th>weekday_5</th>\n",
       "      <th>weekday_6</th>\n",
       "      <th>workingday_0</th>\n",
       "      <th>workingday_1</th>\n",
       "      <th>weathersit_1</th>\n",
       "      <th>weathersit_2</th>\n",
       "      <th>weathersit_3</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <td>630</td>\n",
       "      <td>0.845235</td>\n",
       "      <td>0.835949</td>\n",
       "      <td>0.131896</td>\n",
       "      <td>1.202104</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>...</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>192</td>\n",
       "      <td>1.633352</td>\n",
       "      <td>1.626783</td>\n",
       "      <td>-0.482866</td>\n",
       "      <td>0.126126</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>...</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>275</td>\n",
       "      <td>-0.607994</td>\n",
       "      <td>-0.505423</td>\n",
       "      <td>0.934008</td>\n",
       "      <td>-1.383441</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>...</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>367</td>\n",
       "      <td>-1.888115</td>\n",
       "      <td>-2.137425</td>\n",
       "      <td>-1.311332</td>\n",
       "      <td>2.262059</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>...</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>296</td>\n",
       "      <td>-0.175217</td>\n",
       "      <td>-0.106153</td>\n",
       "      <td>1.013049</td>\n",
       "      <td>-0.925745</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>...</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>658</td>\n",
       "      <td>-0.061324</td>\n",
       "      <td>-0.009285</td>\n",
       "      <td>-0.386260</td>\n",
       "      <td>-0.941951</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>...</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>578</td>\n",
       "      <td>1.214237</td>\n",
       "      <td>1.184860</td>\n",
       "      <td>0.348524</td>\n",
       "      <td>-0.636675</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>...</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>728</td>\n",
       "      <td>-1.323224</td>\n",
       "      <td>-1.424344</td>\n",
       "      <td>0.878392</td>\n",
       "      <td>-0.853552</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>...</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>391</td>\n",
       "      <td>-0.384772</td>\n",
       "      <td>-0.362119</td>\n",
       "      <td>0.796421</td>\n",
       "      <td>1.965022</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>...</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>20</td>\n",
       "      <td>-1.737780</td>\n",
       "      <td>-1.943639</td>\n",
       "      <td>-1.200092</td>\n",
       "      <td>2.101570</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>...</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>584 rows × 36 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "         temp     atemp       hum  windspeed  season_1  season_2  season_3  \\\n",
       "630  0.845235  0.835949  0.131896   1.202104         0         0         1   \n",
       "192  1.633352  1.626783 -0.482866   0.126126         0         0         1   \n",
       "275 -0.607994 -0.505423  0.934008  -1.383441         0         0         0   \n",
       "367 -1.888115 -2.137425 -1.311332   2.262059         1         0         0   \n",
       "296 -0.175217 -0.106153  1.013049  -0.925745         0         0         0   \n",
       "..        ...       ...       ...        ...       ...       ...       ...   \n",
       "658 -0.061324 -0.009285 -0.386260  -0.941951         0         0         0   \n",
       "578  1.214237  1.184860  0.348524  -0.636675         0         0         1   \n",
       "728 -1.323224 -1.424344  0.878392  -0.853552         1         0         0   \n",
       "391 -0.384772 -0.362119  0.796421   1.965022         1         0         0   \n",
       "20  -1.737780 -1.943639 -1.200092   2.101570         1         0         0   \n",
       "\n",
       "     season_4  yr_0  yr_1  ...  weekday_2  weekday_3  weekday_4  weekday_5  \\\n",
       "630         0     0     1  ...          0          0          0          0   \n",
       "192         0     1     0  ...          1          0          0          0   \n",
       "275         1     1     0  ...          0          0          0          0   \n",
       "367         0     0     1  ...          1          0          0          0   \n",
       "296         1     1     0  ...          0          0          0          0   \n",
       "..        ...   ...   ...  ...        ...        ...        ...        ...   \n",
       "658         1     0     1  ...          0          0          0          0   \n",
       "578         0     0     1  ...          0          1          0          0   \n",
       "728         0     0     1  ...          0          0          0          0   \n",
       "391         0     0     1  ...          0          0          0          1   \n",
       "20          0     1     0  ...          0          0          0          1   \n",
       "\n",
       "     weekday_6  workingday_0  workingday_1  weathersit_1  weathersit_2  \\\n",
       "630          1             1             0             1             0   \n",
       "192          0             0             1             1             0   \n",
       "275          0             0             1             0             1   \n",
       "367          0             0             1             1             0   \n",
       "296          0             0             1             1             0   \n",
       "..         ...           ...           ...           ...           ...   \n",
       "658          1             1             0             1             0   \n",
       "578          0             0             1             1             0   \n",
       "728          1             1             0             0             1   \n",
       "391          0             0             1             0             1   \n",
       "20           0             0             1             1             0   \n",
       "\n",
       "     weathersit_3  \n",
       "630             0  \n",
       "192             0  \n",
       "275             0  \n",
       "367             0  \n",
       "296             0  \n",
       "..            ...  \n",
       "658             0  \n",
       "578             0  \n",
       "728             0  \n",
       "391             0  \n",
       "20              0  \n",
       "\n",
       "[584 rows x 36 columns]"
      ]
     },
     "execution_count": 25,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "X_train"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "630    8395\n",
       "192    4258\n",
       "275    3570\n",
       "367    2236\n",
       "296    4187\n",
       "       ... \n",
       "658    8090\n",
       "578    7580\n",
       "728    1341\n",
       "391    3456\n",
       "20     1543\n",
       "Name: cnt, Length: 584, dtype: int64"
      ]
     },
     "execution_count": 26,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "y_train"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>temp</th>\n",
       "      <th>atemp</th>\n",
       "      <th>hum</th>\n",
       "      <th>windspeed</th>\n",
       "      <th>season_1</th>\n",
       "      <th>season_2</th>\n",
       "      <th>season_3</th>\n",
       "      <th>season_4</th>\n",
       "      <th>yr_0</th>\n",
       "      <th>yr_1</th>\n",
       "      <th>...</th>\n",
       "      <th>weekday_2</th>\n",
       "      <th>weekday_3</th>\n",
       "      <th>weekday_4</th>\n",
       "      <th>weekday_5</th>\n",
       "      <th>weekday_6</th>\n",
       "      <th>workingday_0</th>\n",
       "      <th>workingday_1</th>\n",
       "      <th>weathersit_1</th>\n",
       "      <th>weathersit_2</th>\n",
       "      <th>weathersit_3</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <td>count</td>\n",
       "      <td>584.000000</td>\n",
       "      <td>584.000000</td>\n",
       "      <td>584.000000</td>\n",
       "      <td>584.000000</td>\n",
       "      <td>584.000000</td>\n",
       "      <td>584.000000</td>\n",
       "      <td>584.000000</td>\n",
       "      <td>584.000000</td>\n",
       "      <td>584.000000</td>\n",
       "      <td>584.000000</td>\n",
       "      <td>...</td>\n",
       "      <td>584.000000</td>\n",
       "      <td>584.000000</td>\n",
       "      <td>584.000000</td>\n",
       "      <td>584.000000</td>\n",
       "      <td>584.000000</td>\n",
       "      <td>584.000000</td>\n",
       "      <td>584.000000</td>\n",
       "      <td>584.000000</td>\n",
       "      <td>584.000000</td>\n",
       "      <td>584.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>mean</td>\n",
       "      <td>-0.003495</td>\n",
       "      <td>-0.003100</td>\n",
       "      <td>-0.008870</td>\n",
       "      <td>0.031267</td>\n",
       "      <td>0.248288</td>\n",
       "      <td>0.253425</td>\n",
       "      <td>0.261986</td>\n",
       "      <td>0.236301</td>\n",
       "      <td>0.481164</td>\n",
       "      <td>0.518836</td>\n",
       "      <td>...</td>\n",
       "      <td>0.143836</td>\n",
       "      <td>0.159247</td>\n",
       "      <td>0.131849</td>\n",
       "      <td>0.145548</td>\n",
       "      <td>0.147260</td>\n",
       "      <td>0.309932</td>\n",
       "      <td>0.690068</td>\n",
       "      <td>0.635274</td>\n",
       "      <td>0.337329</td>\n",
       "      <td>0.027397</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>std</td>\n",
       "      <td>1.003336</td>\n",
       "      <td>1.007816</td>\n",
       "      <td>1.010637</td>\n",
       "      <td>0.991178</td>\n",
       "      <td>0.432390</td>\n",
       "      <td>0.435345</td>\n",
       "      <td>0.440092</td>\n",
       "      <td>0.425174</td>\n",
       "      <td>0.500073</td>\n",
       "      <td>0.500073</td>\n",
       "      <td>...</td>\n",
       "      <td>0.351224</td>\n",
       "      <td>0.366220</td>\n",
       "      <td>0.338617</td>\n",
       "      <td>0.352955</td>\n",
       "      <td>0.354669</td>\n",
       "      <td>0.462862</td>\n",
       "      <td>0.462862</td>\n",
       "      <td>0.481766</td>\n",
       "      <td>0.473203</td>\n",
       "      <td>0.163378</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>min</td>\n",
       "      <td>-2.175711</td>\n",
       "      <td>-2.288589</td>\n",
       "      <td>-4.411486</td>\n",
       "      <td>-1.913388</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>...</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>25%</td>\n",
       "      <td>-0.873360</td>\n",
       "      <td>-0.844916</td>\n",
       "      <td>-0.782929</td>\n",
       "      <td>-0.710951</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>...</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>50%</td>\n",
       "      <td>-0.006657</td>\n",
       "      <td>0.031406</td>\n",
       "      <td>-0.015942</td>\n",
       "      <td>-0.082597</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>...</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>75%</td>\n",
       "      <td>0.873707</td>\n",
       "      <td>0.824375</td>\n",
       "      <td>0.728358</td>\n",
       "      <td>0.585746</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>...</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>max</td>\n",
       "      <td>2.002355</td>\n",
       "      <td>2.250800</td>\n",
       "      <td>2.421148</td>\n",
       "      <td>4.092936</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>...</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>1.000000</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>8 rows × 36 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "             temp       atemp         hum   windspeed    season_1    season_2  \\\n",
       "count  584.000000  584.000000  584.000000  584.000000  584.000000  584.000000   \n",
       "mean    -0.003495   -0.003100   -0.008870    0.031267    0.248288    0.253425   \n",
       "std      1.003336    1.007816    1.010637    0.991178    0.432390    0.435345   \n",
       "min     -2.175711   -2.288589   -4.411486   -1.913388    0.000000    0.000000   \n",
       "25%     -0.873360   -0.844916   -0.782929   -0.710951    0.000000    0.000000   \n",
       "50%     -0.006657    0.031406   -0.015942   -0.082597    0.000000    0.000000   \n",
       "75%      0.873707    0.824375    0.728358    0.585746    0.000000    1.000000   \n",
       "max      2.002355    2.250800    2.421148    4.092936    1.000000    1.000000   \n",
       "\n",
       "         season_3    season_4        yr_0        yr_1  ...   weekday_2  \\\n",
       "count  584.000000  584.000000  584.000000  584.000000  ...  584.000000   \n",
       "mean     0.261986    0.236301    0.481164    0.518836  ...    0.143836   \n",
       "std      0.440092    0.425174    0.500073    0.500073  ...    0.351224   \n",
       "min      0.000000    0.000000    0.000000    0.000000  ...    0.000000   \n",
       "25%      0.000000    0.000000    0.000000    0.000000  ...    0.000000   \n",
       "50%      0.000000    0.000000    0.000000    1.000000  ...    0.000000   \n",
       "75%      1.000000    0.000000    1.000000    1.000000  ...    0.000000   \n",
       "max      1.000000    1.000000    1.000000    1.000000  ...    1.000000   \n",
       "\n",
       "        weekday_3   weekday_4   weekday_5   weekday_6  workingday_0  \\\n",
       "count  584.000000  584.000000  584.000000  584.000000    584.000000   \n",
       "mean     0.159247    0.131849    0.145548    0.147260      0.309932   \n",
       "std      0.366220    0.338617    0.352955    0.354669      0.462862   \n",
       "min      0.000000    0.000000    0.000000    0.000000      0.000000   \n",
       "25%      0.000000    0.000000    0.000000    0.000000      0.000000   \n",
       "50%      0.000000    0.000000    0.000000    0.000000      0.000000   \n",
       "75%      0.000000    0.000000    0.000000    0.000000      1.000000   \n",
       "max      1.000000    1.000000    1.000000    1.000000      1.000000   \n",
       "\n",
       "       workingday_1  weathersit_1  weathersit_2  weathersit_3  \n",
       "count    584.000000    584.000000    584.000000    584.000000  \n",
       "mean       0.690068      0.635274      0.337329      0.027397  \n",
       "std        0.462862      0.481766      0.473203      0.163378  \n",
       "min        0.000000      0.000000      0.000000      0.000000  \n",
       "25%        0.000000      0.000000      0.000000      0.000000  \n",
       "50%        1.000000      1.000000      0.000000      0.000000  \n",
       "75%        1.000000      1.000000      1.000000      0.000000  \n",
       "max        1.000000      1.000000      1.000000      1.000000  \n",
       "\n",
       "[8 rows x 36 columns]"
      ]
     },
     "execution_count": 27,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "X_train.describe()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "count     584.000000\n",
       "mean     4522.981164\n",
       "std      1930.059694\n",
       "min        22.000000\n",
       "25%      3214.000000\n",
       "50%      4585.500000\n",
       "75%      5922.500000\n",
       "max      8714.000000\n",
       "Name: cnt, dtype: float64"
      ]
     },
     "execution_count": 28,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "y_train.describe()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
